<?php
require 'include.php';
$id = (!empty($_REQUEST['id'])) ? $_REQUEST['id'] : "";
$action = (!empty($_REQUEST['action'])) ? $_REQUEST['action'] : "";
if($id){
	if($action == 'vcard'){
		require("../include/htmlMimeMail.php");
		$membre = new membre($id);
		$output = $membre->vcard();
		$filename = "tmp/".(str_replace(" ","_",$membre->prenom."_".$membre->nom)).".vcf";
		if(file_put_contents($filename,$output)){
			$logged_id = check_cookie();
			$logged = new membre($logged_id);
			$TOs = array($logged->email);
			if(count($TOs)){
				// mail("robin.liechti@vtxnet.ch","test2 avant email","resrdrs");
				$mail = new htmlMimeMail();
				$de = "info@vbcll.ch";
				$titre = "VBCLL : $membre->prenom $membre->nom";
				$corps = "Veuillez trouver en attaché la vcard de $membre->prenom $membre->nom"."\r\n";
				if(get_magic_quotes_gpc()) $corps = stripslashes($corps);
				$attachment = $mail->getFile($filename);	
				$mail->addAttachment($attachment, basename($filename), "text/x-vCard");					
				$mail->setText(wordwrap($corps, 70)); 
				$mail->setFrom($de);
				$mail->setSubject($titre);             
				$result = $mail->send($TOs);
				
				unlink($filename);
				echo "un email vous a été envoyé avec la vCard en pièce jointe";
			}
			else echo "vous n'avez pas d'adresse email enregistrée";
		}
		else echo "désolé, une erreur est survenue";
	}
	else{
		$membre = new membre($id);
		echo leftCol($membre->photo('60',0),30);
		echo rightCol("<h3 style = 'text-align: left'>$membre->prenom $membre->nom</h3>",68);
		echo "<br class = 'clear'/>\n";
		echo "<div class = 'box'>\n";
		$tels = array("tel" => "domicile","mobile" => "mobile","prof" => "professionel");
		$lines = array();
		foreach($tels as $field => $print){
			if($membre->$field){
				ob_start();
				echo leftCol($print,30);
				echo rightCol("<a href='tel:".$membre->$field."'>".$membre->$field."</a>",68);
				$lines[] = ob_get_clean();
			}
		}
		if(count($lines)){
			echo implode("<br class = 'clear' /><hr style = 'margin-left: -10px; margin-right: -10px; '/>\n",$lines);
			echo "<br class = 'clear' />\n";
		}
		echo "</div>\n";
		if($membre->email){
			echo "<div class = 'box' style = 'margin-top: 20px;'>\n";
			echo leftCol("email",30);
			echo rightCol("<a href = 'mailto: $membre->email'>$membre->email</a>",68);
			echo "<br class = 'clear' />\n";
			echo "</div>\n";
		}
		if(check_cookie()){
			echo "<div class = 'box' style = 'margin-top: 20px;'>\n";
			echo leftCol("adresse",30);
			echo rightCol("<a href='http://maps.google.com/maps?q=".(str_replace(" ","+",$membre->adresse)).",+".(str_replace(" ","+",$membre->localite))."+switzerland'>$membre->adresse<br />$membre->npa $membre->localite</a>",68);
			echo "<br class = 'clear' />\n";
			echo "</div>\n";		
			echo "<div class = 'box' style = 'margin-top: 20px;'>\n";
			echo leftCol("anniversaire",30);
			$months = array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
			$mois = array("janvier","f&eacute;vrier","mars","avril","mai","juin","juillet","ao&ucirc;t", "septembre","octobre","novembre","d&eacute;cembre");
			echo rightCol(str_replace($months,$mois,format_date($membre->ddn,"d M")),68);
			echo "<br class = 'clear' /><hr style = 'margin-left: -10px; margin-right: -10px; '/>\n";
			echo leftCol("equipes",30);
			echo rightCol(implode("; " , $membre->equipes),68);
			echo "<br class = 'clear' />\n";
			echo "</div>\n";		
			echo "<div class = 'box' style = 'margin-top: 20px;'>\n";
			echo leftCol("Vcard",30);
			echo rightCol("<img src = 'images/icon_vcard.png' alt = 'vcard' height = '23' width = '29' onclick = 'vcard($id)' />",68);
			echo "<br class = 'clear' />\n";
			echo "</div>\n";

		}		

	}
}
?>